package parse;

import java.util.ArrayList;
import java.util.List;

import Const.Constant;
import Const.RC;
import RecordManagement.*;
import SystemManagement.DataAttrInfo;
import SystemManagement.SM_Manager;

public class DeleteTuple extends SQL{
	public String relName;
	public Condition conditions;
	
	public DeleteTuple(String relname, Condition con){
		this.relName = relname;
		this.conditions = con;
	}
	
	public LQPlan CrtAgbPlan(SM_Manager sm){
		try{
			sm.CheckTable(relName);
		}
		catch(Error e){
			throw e;
		}
		
		AlgebraTable table = new AlgebraTable(this.relName);
		Sigma sigma = new Sigma(this.conditions, table);
		return new LQPlan(new Delete_LQplan(sigma));
	}
	
//	public void delete(SM_Manager sm){
//		RM_Manager rm = sm.rm;
//		RM_FileHandle filehandle = null;
//		
//		try{
//			filehandle = rm.OpenFile(relName + ".db");
//		}
//		catch(java.io.IOException e){
//	   		System.out.println("File not found");
//    		return;
//		}
//		
//		ScanType st = new ScanType(ScanType.TYPE_STRING, 
//                                   Constant.MAXNAME, 0, ScanType.OP_NO,
//                                   null, ScanType.PIN_NORMAL);
//
//    	RM_FileScan fileScan = new RM_FileScan(filehandle, st);
//    	
//    	RM_Record record = null;
//    	while((record = fileScan.GetNextRec())!=null){
//    		if(Check())
//    			filehandle.DeleteRec(record.GetRid());
//    	}
//    	
//    	rm.CloseFile(filehandle);
//    	fileScan.CloseScan();
//	}
}
